package com.feng.test.aatest

/**
 * @author HuangSuip
 */
object TestString1 {
    @JvmStatic
    fun main(args: Array<String>) {
        //test1();
        test2()
    }

    private fun test2() {
        val s = "afa.faf.123.456"
        println(s.substring(0, s.lastIndexOf(".")))

    }

    private fun test1() {
        var s1 = "";
        var s2 = "";
        var s3 = 0;
        println("-----------")
        s1 = "adf"
        s2 = "adf"
        println(addBinary(s1, s2))
        println(s1[0].toInt() - 0)
        println('0'.toInt() - 0)
        println(s1[0] - '0')
        println("-----------")

        val l: Long? = null
        println(l!!.toString() + "")
    }

    fun addBinary(a: String, b: String): String {

        val result = StringBuilder()

        var carry = 0

        var i = a.length - 1
        var j = b.length - 1

        while (i >= 0 || j >= 0) {

            var sum = carry
            if (i >= 0) sum += a[i--] - '0'
            if (j >= 0) sum += b[j--] - '0'
            result.append(sum % 2)
            carry = sum / 2

        }

        if (carry != 0) result.append(carry)
        return result.reverse().toString()

    }
}
